//
//  HMHomeTableViewCell.swift
//  微博
//
//  Created by 程双岐 on 16/9/23.
//  Copyright © 2016年 heima. All rights reserved.
//

import UIKit

//首页自定义cell
/*
    1 原创微博试图
    2 转发微博试图
    3 底部toolBar试图
 */

let HMHHomeTableViewCellMargin: CGFloat = 10

class HMHomeTableViewCell: UITableViewCell {
    
    var toolBarTopConstraint: Constraint?
    
    var statusViewModel: HMStadusViewModel?{
        didSet{
            yuanChuangView.statusViewModel = statusViewModel
            toolbar.statusViewModel = statusViewModel
            
            toolBarTopConstraint?.uninstall()
            
            if statusViewModel?.status?.retweeted_status != nil {
                retweetView.isHidden = false
                
                toolbar.snp_updateConstraints(closure: { (make) in
                    toolBarTopConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
                })
                retweetView.statusViewModel = statusViewModel

                
            }  else{
                
                retweetView.isHidden = true
                toolbar.snp_updateConstraints(closure: { (make) in
                    toolBarTopConstraint = make.top.equalTo(yuanChuangView.snp_bottom).constraint
                })
                
            }
        }
    }
    
    
    private lazy var yuanChuangView: HMStatusYuanChuangView = {
       let view = HMStatusYuanChuangView()
//        view.backgroundColor = RandomColor()
        return view
    }()
    
    private lazy var toolbar: HMStatusToolBar = HMStatusToolBar()
    
    private lazy var retweetView: HMStatusRetweetView = {
       let view = HMStatusRetweetView()
//        view.backgroundColor = RandomColor()
        return view
    }()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        contentView.backgroundColor = UIColor(white: 0.95, alpha: 1)
        contentView.addSubview(yuanChuangView)
        contentView.addSubview(toolbar)
        contentView.addSubview(retweetView)
        yuanChuangView.snp_makeConstraints { (make) in
            make.top.equalTo(contentView).offset(8)
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
        }
        retweetView.snp_makeConstraints { (make) in
            make.top.equalTo(yuanChuangView.snp_bottom)
            make.leading.equalTo(yuanChuangView)
            make.trailing.equalTo(yuanChuangView)
        }
        
        toolbar.snp_makeConstraints { (make) in
            make.top.equalTo(retweetView.snp_bottom)
            make.leading.equalTo(self)
            make.trailing.equalTo(self)
            make.height.equalTo(35)
            make.bottom.equalTo(contentView.snp_bottom)
        }
//        contentView.snp_makeConstraints { (make) in
//            make.bottom.equalTo(toolbar)
//            make.top.equalTo(self)
//            make.leading.equalTo(self)
//            make.trailing.equalTo(self)
//        }
        
        
    }
    
    
}
